package com.example.project;

import com.example.project.db.DBHelper;

import android.app.Fragment;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class DescFragment extends Fragment {
	int mNowIndex;
	private DBHelper mDbManager;
	Cursor cursor = null;
	String list_no;
	StringBuilder sb = new StringBuilder();

	public static DescFragment newInstance(int index, String list_no) {
		DescFragment df = new DescFragment();
		df.mNowIndex = index;
		df.list_no = list_no;
		return df;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mDbManager = DBHelper.getInstance(getActivity());
		cursor = mDbManager.select(list_no);
		boolean isfirst = true;
		if (cursor.moveToFirst()) {
			int n_mysql = cursor.getColumnIndex("mysql");
			int n_oracle = cursor.getColumnIndex("oracle");
			int n_sqlserver = cursor.getColumnIndex("sqlserver");
			int n_query = cursor.getColumnIndex("query");
			int n_description = cursor.getColumnIndex("description");
			do {
				if(cursor.getInt(n_mysql)==1){
					sb.append("mySQL");
					isfirst = false;
				}
				if(cursor.getInt(n_oracle)==1){
					if(!isfirst){
						sb.append(", ");
					}
					sb.append("Oracle");
					isfirst = false;
				}
				if(cursor.getInt(n_sqlserver)==1){
					if(!isfirst){
						sb.append(", ");
					}
					sb.append("SqlServer");
				}
				sb.append(":\n");				
				sb.append("\t함수(" + cursor.getString(n_query) + ")\n");
				String description = cursor.getString(n_description);
				Log.d("print", description + "");
				sb.append("\t"+description + "\n");
				sb.append("\n--------------------------------------\n\n");
				isfirst = true;
			} while (cursor.moveToNext());
			cursor.close();
		}
		View root = inflater.inflate(R.layout.descfragment, container, false);
		TextView text = (TextView) root
				.findViewById(R.id.descfragment_txtdescription);
		text.setText(sb);
		return root;
	}
}